//添加内容
var addhtml=''
addhtml+='<div class="form-div"><form id="fomr">';
addhtml+='<div class="layui-form-item layui-form-select-icon iconfont"><label class="layui-form-label">货币</label><div class="layui-input-block"><select name="coin_id" lay-ignore class="layui-input   cion-type"></select></div></div>';
addhtml+='<div class="layui-form-item"><label class="layui-form-label">转账比率</label><div class="layui-input-block"><input type="text" name="config" autocomplete="off" placeholder="请输入货币提现比率" class="layui-input"></div></div>';
addhtml+='<input type="hidden" value="'+configType+'" name="type">';
addhtml+='<input type="hidden" name="token" value="'+token+'">';
addhtml+='</form></div>';



//编辑内容
var edithtml=''
edithtml+='<div class="form-div"><form id="fomr">';
edithtml+='<input type="hidden" name="id">';
edithtml+='<div class="layui-form-item layui-form-select-icon iconfont"><label class="layui-form-label">货币</label><div class="layui-input-block"><select name="coin_id" lay-ignore class="layui-input   cion-type"></select></div></div>';
edithtml+='<div class="layui-form-item"><label class="layui-form-label">转账比率</label><div class="layui-input-block"><input type="text" name="config" autocomplete="off" placeholder="请输入货币提现比率" class="layui-input"></div></div>';
edithtml+='<input type="hidden" value="'+configType+'" name="type">';
edithtml+='<input type="hidden" name="token" value="'+token+'">';
edithtml+='</form></div>';





layui.use('table', function() {
	var table = layui.table;
	
	var $ = layui.$, active = {
		//添加货币
	 	add: function(){
	      layer.open({
			  type: 1,
			  title:"新增转账配置",
			  area: ['550px', '240px'], //宽高
			  maxmin: true,
			  resize:true,
			  content: addhtml,
			  btn: ['提交', '关闭'],
			  btn1: function(){
			  	var Adata=$("#fomr").serialize();
			    $.ajax({
			    	type:'post',
			    	dataType:'json',
			    	url:addSrc,
			    	data:Adata,
			    	success:function(data){
			    		var code=data.code;
			    		var msg=data.msg;
			    		if(code==1){
			    			layer.close(layer.index)
			    			layer.alert(msg,{icon: 1},function(){
			    				location.reload();
			    			})
			    		}else{
			    			layer.alert(msg,{icon: 5})
			    		}
			    	}
			    })
			  }
			});
			$("#fomr select.cion-type").html($("#cionHtml").html());
	    }
	 }
	 $('.right-center .right-btn').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	});
	
	
    layer.msg('数据加载中...', {
		icon: 16,
		shade: 0.3,
		success: function() {
			$.ajax({
				type: 'post',
				dataType: 'json',
				url: listSrc,
				data:{
					type:configType
				},
				success: function(data) {
					var arr = []
					$.each(data, function(index,value) {
						arr.push(value);
					});
					table.render({
						elem: '#centet-cen',
						height: $(".center-tab").height(),
						id:'idTest',
						cols: [
							[ //标题栏
								{
									field: 'id',
									title: 'ID',
									width: 60
								}, {
									field: 'coin_name',
									title: '货币名称',
									width: 200
								}, {
									field: 'config',
									title: '转帐比率',
									width: 200
								}, {
									field: 'oper',
									title: '操作',
									minWidth: 160,
									toolbar: '#barDemo'
								}

							]
						],
						data: arr,
						limit: 200
					});
					var pageHtml = data.page_html;
					$(".paging").html(pageHtml);
					layer.close(layer.index);
				}
			});
		}
	})
    
    
    table.on('tool(table)', function(obj) {
    	
    	var data = obj.data;
    	
    	if(obj.event === 'edit') {
    		var id = data.id;
    		$.ajax({
		    	type:'post',
		    	url:seeSrc,
		    	data:{
		    		id:id
		    	},
		    	success:function(data){
		    		var code=data.code;
		    		var msg=data.msg;
		    			layer.open({
		    			  title:"编辑货币转账配置",
						  type: 1,
						  skin: 'layui-layer-rim',
						  area: ['550px', '240px'],
						  content: edithtml,
						  btn: ['提交', '关闭'],
						  btn1: function(){
						  	var Adata=$("#fomr").serialize();
						    $.ajax({
						    	type:'post',
						    	dataType:'json',
						    	url:editSrc,
						    	data:Adata,
						    	success:function(data){
						    		var code=data.code;
						    		var msg=data.msg;
						    		if(code==1){
						    			layer.close(layer.index)
						    			layer.alert(msg,{icon: 1},function(){
						    				location.reload();
						    			})
						    		}else{
						    			layer.alert(msg,{icon: 5})
						    		}
						    	}
						    })
						  }
						});
						$("#fomr select.cion-type").html($("#cionHtml").html());
						$("#fomr").formEdit(data);
		    	}
		    })
    	}else if(obj.event === 'del'){
    		var id = data.id;
    		layer.alert('您确定要删除该转账配置！',{
				icon: 2,
				btn: ['确定', '关闭'],
				btn1: function(){
					$.ajax({
				    	type:'post',
				    	dataType:'json',
				    	url:delSrc,
				    	data:{
				    		token:token,
				    		id:id
				    	},
				    	success:function(data){
				    		var code=data.code;
				    		var msg=data.msg;
				    		if(code==1){
				    			layer.close(layer.index)
				    			layer.alert(msg,{icon: 1},function(){
				    				location.reload();
				    			})
				    		}else{
				    			layer.close(layer.index)
				    			layer.alert(msg,{icon: 5})
				    		}
				    	}
				    })
				}
			})
    	}
    	
    	
    })
})



$(function(){
	
	cionFun();
	
})